package com.lwd.springcloud.billmanagement.controller;

import com.lwd.springcloud.billmanagement.entity.Bill;
import com.lwd.springcloud.billmanagement.service.BillService;
import com.lwd.springcloud.billmanagement.service.TypeService;
import com.lwd.springcloud.billmanagement.util.DateConverterConfig;
import com.lwd.springcloud.billmanagement.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("bill")
public class BillController {
    @Resource
    private BillService billService;

    /**
     * 查询
     */
    @GetMapping("list")
    public ResultVO<Bill> list(Bill b) {
        return new ResultVO<>(billService.list(b));
    }

    /**
     * 查询
     */
    @GetMapping("list-page")
    public ResultVO<Bill> listPage(
            @RequestParam(name = "page", defaultValue = "1") int pageNum,
            @RequestParam(name = "limit", defaultValue = "10") int pageSize,
            Bill b) {
        return new ResultVO<>(billService.listPage(b, pageNum, pageSize));
    }

    @GetMapping("{id}")
    public ResultVO<Bill> info(@PathVariable("id") Long id) {
        return new ResultVO<>(
                billService.get(id)
        );
    }

    /**
     * 添加
     */
    @PostMapping
    public ResultVO<Boolean> add(Bill b) {
        return new ResultVO<>(billService.add(b) > 0);
    }

    /**
     * 删除
     */
    @DeleteMapping("{id}")
    public ResultVO<Boolean> delete(@PathVariable("id") Long id) {
        return new ResultVO<>(billService.delete(id) > 0);
    }

    /**
     * 修改
     */
    @PutMapping("{id}")
    public ResultVO<Boolean> update(@PathVariable("id") Long id, Bill b) {
        b.setId(id);
        return new ResultVO<>(billService.update(b) > 0);
    }
}
